<?php

use console\db\channels\TransferTableMigration;
use yii\db\Query;

/**
 * 交易订单转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m310000_000001_t_vipcard_trade_order extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * 是否先清理本地数据表
     */
    public $beforeTruncateTargetTable = false;

    /**
     * @inheritdoc
     */
    public function buildQuery() {
        return (new Query())->from('{{%' . $this->sourceTable . '}}')->where(['>', 'id', 73791]);
    }

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'trade_order' => 'trade_order',
            ],
            'columns' => [
                'original_no' => 'tn',
                'paymode',
                'pay_type' => 'type',
                'pay_no' => 'pn',
                'currency',
                'pay',
                'pay_time' => 'paytime',
                'expire_time' => 'expiretime',
                'account_id' => function($data) {
                    if ($data['status'] == -9) {
                        return 5;
                    }
                    return 0;
                },
                'status' => function($data) {
                    if ($data['status'] > 0) {
                        return 1;
                    }
                    if ($data['status'] == -9) {
                        return 1;
                    }
                    return $data['status'];
                },
                'created_at' => 'inputtime',
                'updated_at' => 'paytime',
                'mark' => 'id'
            ]
        ];
    }

}
